package com.socket.client;

import java.io.Serializable;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
 * The proxy for service.
 * @author luo
 *
 */
public class ServiceProxy implements InvocationHandler, Serializable{
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 6826716497369894078L;
	private Class<?> api;
	
	public ServiceProxy(Class<?> api){
		this.api = api;
	}

	@Override
	public Object invoke(Object proxy, Method method, Object[] args)
			throws Throwable {
		System.out.println("enter");
		Request msg = new Request();
		//msg.setReturnType(User.class.getName());
		msg.setServer(api.getName());
		msg.setMethodName(method.getName());
		msg.setParams(args);

		//send the request to the server
		Object obj = new Client("1111",msg).sendRequest();
//		if(obj instanceof User){
//			return obj;
//		}
		return obj;
	}

}
